home *** CD-ROM | disk | FTP | other *** search
/ Chip 1998 September / CHIP Eylül 1998.iso / Slackwar / docs / mini / Linux+FreeBSD < prev    next >
Text File  |  1997-02-08  |  17KB  |  405 lines

  1.   The Linux+FreeBSD mini-HOWTO
  2.   Niels Kristian Bech Jensen, nkbj@image.dk
  3.   v1.4, 23 January 1998
  4.  
  5.   This document describes how to use Linux and FreeBSD on the same sys¡
  6.   tem. It introduces FreeBSD and discuss how the two operating systems
  7.   can interact, e.g.  by sharing swap space. You should probably have
  8.   some experience with Linux and hard drive partitioning (fdisk) before
  9.   you read this document. Do not hesitate to mail me if you have com¡
  10.   ments, questions or suggestions about this document. I would also like
  11.   to hear from people who have experience using Linux together with
  12.   NetBSD or OpenBSD.
  13.  
  14.   1.  What is FreeBSD?
  15.  
  16.   FreeBSD is a free Unix-like operating system much like Linux. The main
  17.   difference is that, while the Linux kernel has been written from
  18.   scratch, FreeBSD is based on the freely redistributable parts of
  19.   4.4BSD (Berkeley Software Distribution) known as 4.4BSD-lite. This
  20.   fact might lead some people to suggest that FreeBSD is closer to being
  21.   ``real'' UNIX(TM) than Linux. FreeBSD runs only on the Intel PC
  22.   platform (i386 and higher); a port to the DEC Alpha platform is being
  23.   discussed at the moment. Hardware requirements for FreeBSD are much
  24.   like those for Linux.
  25.  
  26.   The development of FreeBSD is more ``closed'' than the Linux
  27.   development. A core team of developers makes the key decisions
  28.   concerning the project. Big changes are discussed in advance on the
  29.   mailing lists. The FreeBSD project has two development trees (just
  30.   like Linux): ``-current'' and ``-stable''. The ``-current''
  31.   development tree is where the development of new features is going on,
  32.   while changes to the ``-stable'' tree mainly are bug fixes.
  33.  
  34.   FreeBSD can be used and (re-)distributed freely just as Linux. Most
  35.   parts of the system are released under the BSD copyright; the rest is
  36.   under the GNU GPL or the GNU LGPL.
  37.  
  38.   You can find more information about FreeBSD (and download the whole
  39.   system) at FreeBSD Inc. <http://www.freebsd.org/>. The newest
  40.   ``-stable'' releases and snapshots of the ``-current'' development
  41.   code are sold on CDROMs by Walnut Creek CDROM <http://www.cdrom.com/>
  42.   (their web- and ftp-servers are running FreeBSD.)
  43.  
  44.   2.  The FreeBSD way of labelling hard drives
  45.  
  46.   Linux and FreeBSD label hard drives and partitions after two
  47.   differents schemes. This section explains the main differences between
  48.   the two schemes.
  49.  
  50.   2.1.  FreeBSD ``slices'' and ``partitions''
  51.  
  52.   FreeBSD needs only one entry in the primary partition table on your
  53.   hard drive. This primary partition is called a ``slice'' in FreeBSD
  54.   terminology. It then uses the program disklabel to make several
  55.   logical partitions in this primary partition. These logical partitions
  56.   are called ``partitions'' in FreeBSD terminology. This concept is
  57.   similar to the way Linux (and DOS) handles logical partitions in an
  58.   extended partition. Note that the Linux fdisk program doesn't display
  59.   the partitions in a FreeBSD slice from the main menu, but it can
  60.   display BSD disklabel information if you give the command `b'. The
  61.   output is something like this (/dev/hda4 is the FreeBSD slice):
  62.  
  63.   # fdisk /dev/hda
  64.  
  65.   Command (m for help): p
  66.  
  67.   Disk /dev/hda: 64 heads, 63 sectors, 621 cylinders
  68.   Units = cylinders of 4032 * 512 bytes
  69.  
  70.      Device Boot   Begin    Start      End   Blocks   Id  System
  71.   /dev/hda1   *        1        1       27    54400+  83  Linux native
  72.   /dev/hda2           28       28       55    56448   83  Linux native
  73.   /dev/hda3           56       56      403   701568   83  Linux native
  74.   /dev/hda4          404      404      621   439488   a5  BSD/386
  75.  
  76.   Command (m for help): b
  77.   Reading disklabel of /dev/hda4 at sector 1624897.
  78.  
  79.   BSD disklabel command (m for help): p
  80.  
  81.   8 partitions:
  82.   #        size   offset    fstype   [fsize bsize   cpg]
  83.     a:    64512  1624896    4.2BSD        0     0     0   # (Cyl.  404 - 419)
  84.     b:   104832  1689408      swap                        # (Cyl.  420 - 445)
  85.     c:   878976  1624896    unused        0     0         # (Cyl.  404 - 621)
  86.     e:    64512  1794240    4.2BSD        0     0     0   # (Cyl.  446 - 461)
  87.     f:   645120  1858752    4.2BSD        0     0     0   # (Cyl.  462 - 621)
  88.  
  89.   BSD disklabel command (m for help): q
  90.   #
  91.  
  92.   The letters `a'...`f' in the first column are the same labels as shown
  93.   below in the example for a FreeBSD slice. The letter `b' designates
  94.   the swap partition while `c' designates the whole slice. See the
  95.   FreeBSD documentation for more information on the ``standard'' way of
  96.   assigning these letters to different partition types.
  97.  
  98.   2.2.  Drive and partition labelling in Linux and FreeBSD
  99.  
  100.   The hard drives are labelled in the following way in Linux and
  101.   FreeBSD:
  102.  
  103.                                Linux           FreeBSD
  104.        First IDE drive         /dev/hda        /dev/wd0
  105.        Second IDE drive        /dev/hdb        /dev/wd1
  106.        First SCSI drive        /dev/sda        /dev/sd0
  107.        Second SCSI drive       /dev/sdb        /dev/sd1
  108.  
  109.   The partitions (FreeBSD slices) on a drive are labelled in the
  110.   following way (/dev/hda is used as an example):
  111.  
  112.                                        Linux           FreeBSD
  113.        First primary partition         /dev/hda1       /dev/wd0s1
  114.        Second primary partition        /dev/hda2       /dev/wd0s2
  115.        Third primary partition         /dev/hda3       /dev/wd0s3
  116.        Fourth primary partition        /dev/hda4       /dev/wd0s4
  117.  
  118.   The partitions in a FreeBSD slice is labelled in the following way
  119.   (/dev/hda4 is the FreeBSD slice in the example):
  120.  
  121.        Linux label     FreeBSD label   Default FreeBSD mount point
  122.        /dev/hda5       /dev/wd0s4a     /
  123.        /dev/hda6       /dev/wd0s4b     swap
  124.        /dev/hda7       /dev/wd0s4e     /var
  125.        /dev/hda8       /dev/wd0s4f     /usr
  126.  
  127.   If you run dmesg in Linux you will see this as (The linux kernel must
  128.   be build with UFS support for this to work. See section ``Installing
  129.   and preparing Linux''):
  130.  
  131.        Partition check:
  132.         hda: hda1 hda2 hda3 hda4 < hda5 hda6 hda7 hda8 >
  133.  
  134.   If you have installed FreeBSD in the /dev/sdb3 slice, and /dev/sdb2 is
  135.   a Linux extended partition containing two logical partitions
  136.   (/dev/sdb5 and /dev/sdb6), the previous example would look like this:
  137.  
  138.        Linux label     FreeBSD label   Default FreeBSD mount point
  139.        /dev/sdb7       /dev/sd1s3a     /
  140.        /dev/sdb8       /dev/sd1s3b     swap
  141.        /dev/sdb9       /dev/sd1s3e     /var
  142.        /dev/sdb10      /dev/sd1s3f     /usr
  143.  
  144.   This will be shown as
  145.  
  146.        Partition check:
  147.         sdb: sdb1 sdb2 < sdb5 sdb6 > sdb3 < sdb7 sdb8 sdb9 sdb10 >
  148.  
  149.   in the output from dmesg.
  150.  
  151.   If you have a Linux extended partition after your FreeBSD slice your
  152.   in for trouble. Since most Linux kernels installation floppies are
  153.   build without UFS support, they will not recognise the FreeBSD
  154.   partitions inside the slice. What should have have been seen as
  155.   (/dev/hda3 is the FreeBSD slice and /dev/hda4 is the Linux extended
  156.   partition)
  157.  
  158.        Partition check:
  159.         hda: hda1 hda2 hda3 < hda5 hda6 hda7 hda8 > hda4 < hda9 hda10 >
  160.  
  161.   is seen as:
  162.  
  163.   Partition check:
  164.    hda: hda1 hda2 hda3 hda4 < hda5 hda6 >
  165.  
  166.   This can give you the wrong device assignment and cause the loss of
  167.   data. My advice is to always put your FreeBSD slice after any Linux
  168.   extended partitions, and do not change any logical partitions in your
  169.   Linux extended partitions after installing FreeBSD!
  170.  
  171.   3.  Sharing swap space between Linux and FreeBSD
  172.  
  173.   This section describes how I got Linux and FreeBSD to share a swap
  174.   partition.  There may be other ways to get the same result. This is
  175.   based on Red Hat Linux release 4.1 and 4.2 (Linux kernel 2.0.29 and
  176.   2.0.30) and FreeBSD 2.2.2. You can install FreeBSD before Linux if you
  177.   want to, just pay attention to the order of the partitions in the
  178.   FreeBSD slice.
  179.  
  180.   3.1.  Installing and preparing Linux
  181.  
  182.   The first step is to install Linux as normal. You have to leave space
  183.   for the FreeBSD slice at you hard drive. You don't have to make a
  184.   Linux swap partition, but if you want one, put it in the space you
  185.   want to allocate for FreeBSD. That way you can delete the Linux swap
  186.   partition later and use the space for FreeBSD.
  187.  
  188.   When you have installed Linux you have to build a new kernel. Read The
  189.   Linux Kernel HOWTO if this is new to you. You have to include UFS file
  190.   system support and BSD disklabel (FreeBSD partition tables) support.
  191.  
  192.        UFS filesystem support (read only) (CONFIG_UFS_FS) [N/y/m/?] y
  193.        BSD disklabel (FreeBSD partition tables) support (CONFIG_BSD_DISKLABEL) [N/y/?]
  194.        (NEW) y
  195.  
  196.   Install the new kernel and reboot. Remove any line including the word
  197.   swap from your /etc/fstab file if you have made a Linux swap
  198.   partition.  Make sure you have a working Linux boot disk with the new
  199.   kernel. You are now ready to install FreeBSD.
  200.  
  201.   3.2.  Installing FreeBSD
  202.  
  203.   Install FreeBSD as described in the FreeBSD documentation. Remove the
  204.   Linux swap partition is you have made one (you can use the FreeBSD
  205.   fdisk program.) Pay attention to the order of the partitions in the
  206.   FreeBSD slice. If you use the default labelling the second partition
  207.   will be the swap partition. Complete the installation of FreeBSD and
  208.   reboot into Linux using the new Linux boot disk.
  209.  
  210.   3.3.  Setting up the FreeBSD swap partition in Linux
  211.  
  212.   Run dmesg when you have booted into Linux. In the output you should
  213.   see something like this:
  214.  
  215.   Partition check:
  216.    hda: hda1 hda2 hda3 hda4 < hda5 hda6 hda7 hda8 >
  217.  
  218.   This means that /dev/hda4 is your FreeBSD slice, while /dev/hda5,
  219.   /dev/hda6, /dev/hda7 and /dev/hda8 are the FreeBSD partitions. If your
  220.   swap partition is the second partition in the slice, it will be
  221.   /dev/hda6.
  222.  
  223.   You have to put the following line into your /etc/fstab file to enable
  224.   the swap partition:
  225.  
  226.        /dev/hda6       none            swap            sw              0       0
  227.  
  228.   While FreeBSD can use any type of partition as swap space, Linux needs
  229.   a special signature in the swap partition. This signature is made by
  230.   mkswap.  FreeBSD ruins this signature when it uses the shared swap
  231.   partition, so you will have to run mkswap each time you boot into
  232.   Linux. To do this automagically you have to find the script that runs
  233.   swapon at boot time.  In Red Hat Linux it is /etc/rc.d/rc.sysinit. Put
  234.   the following line into that file just before swapon -a:
  235.  
  236.        awk -- '/swap/ && ($1 !~ /#/) { system("mkswap "$1"") }' /etc/fstab
  237.  
  238.   This will run mkswap on any swap partitions in /etc/fstab every time
  239.   you boot except if they are commented out (having ``#'' as the first
  240.   character in the line.)
  241.  
  242.   Run free to check out the size of the swap space when you have
  243.   rebooted into Linux. You should also reboot into FreeBSD to make sure
  244.   everything works as expected. If it does not, you have probably used
  245.   the wrong partition as swap partition. The only solution to that
  246.   problem is to reinstall FreeBSD and try again. Experience is a great
  247.   teacher. :-)
  248.  
  249.   4.  Booting FreeBSD using LILO
  250.  
  251.   You can easily boot FreeBSD with LILO. Do not install the FreeBSD boot
  252.   loader (Booteasy) if you want to use LILO. Append the following lines
  253.   to your /etc/lilo.conf file and run lilo (the FreeBSD slice being
  254.   /dev/hda4):
  255.  
  256.        other=/dev/hda4
  257.                table=/dev/hda
  258.                label=FreeBSD
  259.  
  260.   If you have installed FreeBSD on the second SCSI drive, use something
  261.   like this (the FreeBSD slice being /dev/sdb2):
  262.        other=/dev/sdb2
  263.                table=/dev/sdb
  264.                loader=/boot/chain.b
  265.                label=FreeBSD
  266.  
  267.   5.  Mounting file systems
  268.  
  269.   5.1.  Mounting UFS file systems under Linux
  270.  
  271.   Unfortunately the UFS support in the Linux kernel is broken. When you
  272.   try to mount a UFS file system, you just get some error messages (the
  273.   file system actually gets mounted, but you cannot read anything from
  274.   it.)
  275.  
  276.   However, there is a new (ALPHA) version of the UFS file system support
  277.   for Linux 2.0.xx kernels (xx <= 30) on SunSite
  278.   <ftp://sunsite.unc.edu/pub/Linux/ALPHA/ufs/>. It is called U2FS and
  279.   the current version is u2fs-0.4.3.tar.gz. U2FS is installed in the
  280.   following way (assuming u2fs-0.4.3.tar.gz is stored in /usr/src):
  281.  
  282.        cd /usr/src
  283.        tar xvzf u2fs-0.4.3.tar.gz
  284.        patch -p0 -E < u2fs-0.4.3.patch
  285.  
  286.   Versions of U2FS for Linux kernels 2.0.31 and higher
  287.   (u2fs-0.4.4.tar.gz) and for the latest 2.1.xx kernels can be found at
  288.   this site <http://www.image.dk/~nkbj/u2fs/>.
  289.  
  290.   Now you have to build a new kernel with support for the U2FS file
  291.   system and BSD disklabel. See section ``Installing and preparing
  292.   Linux'' for more information on this. You can leave out UFS file
  293.   system support from the kernel when you use U2FS.
  294.  
  295.   When you have installed the new kernel, you can mount your UFS file
  296.   systems (all the partitions in the FreeBSD slice except the swap
  297.   partition) with a command like this:
  298.  
  299.        mount -t u2fs /dev/hda8 /mnt
  300.  
  301.   The UFS support is read-only. That is; you can read from the UFS file
  302.   systems but you cannot write to them.
  303.  
  304.   5.2.  Mounting ext2fs file systems under FreeBSD
  305.  
  306.   To mount ext2fs file systems under FreeBSD, you first have to build a
  307.   new kernel with ext2fs support. Read the FreeBSD documentation to
  308.   learn how to do that. Put the line
  309.  
  310.   options         "EXT2FS"
  311.  
  312.   in your kernel configuration file for the new kernel.
  313.  
  314.   When you have booted with the new kernel, you can mount an ext2fs file
  315.   system by giving a command like:
  316.  
  317.        mount -t ext2fs /dev/wd0s3 /mnt
  318.  
  319.   Note that you cannot mount ext2fs file systems in extended partitions
  320.   from FreeBSD.
  321.  
  322.   Due to a bug in FreeBSD you will have to unmount all ext2fs file
  323.   systems before you shut down FreeBSD. If you shut down FreeBSD with an
  324.   ext2fs file system mounted, FreeBSD cannot sync the UFS file systems.
  325.   This results in fsck being run the next time FreeBSD is booted. This
  326.   bug is reported to have been fixed in the ``-current'' development
  327.   tree.
  328.  
  329.   6.  Running foreign binaries
  330.  
  331.   6.1.  Running FreeBSD binaries under Linux
  332.  
  333.   The iBCS package has support for running FreeBSD binaries under Linux;
  334.   but it's old and unmaintained. I can't get it to work. Please let me
  335.   know if you have had better luck with this.
  336.  
  337.   6.2.  Running Linux binaries under FreeBSD
  338.  
  339.   FreeBSD has the ability to run Linux binaries, both in a.out and ELF
  340.   formats.  To do this you have to take the following three steps:
  341.  
  342.   1. You have to enable Linux compatibility. To do this (in FreeBSD
  343.      2.2.2 --- details may vary in other versions) you have to edit your
  344.      /etc/rc.conf file and change
  345.  
  346.        linux_enable="NO"
  347.  
  348.   to
  349.  
  350.        linux_enable="YES"
  351.  
  352.   2. You have to install the Linux shared libraries. They are included
  353.      in FreeBSD 2.2.2 as the package linux_lib-2.4.tgz (a newer version
  354.      might be out now.) Run the command
  355.  
  356.   pkg_add <path_to_package>/linux_lib-2.4.tgz
  357.  
  358.   to install the package. <path_to_package> is the directory where the
  359.   package is stored.
  360.  
  361.   3. Install the Linux program(s) you want to run. The program(s) can be
  362.      installed on either UFS or ext2fs file systems. See section
  363.      ``Mounting ext2fs file systems under FreeBSD'' for more information
  364.      about using ext2fs file systems under FreeBSD.
  365.  
  366.   I have successfully run the Linux versions of Applixware 4.3 and
  367.   Netscape 3.01 (both ELF format) under FreeBSD 2.2.2 using this method
  368.   (yes, I know there is a native FreeBSD version of Netscape 4.) Read
  369.   the FreeBSD documentation for more information on this topic.
  370.  
  371.   7.  References and other documents of interest
  372.  
  373.   The newest version of this mini-HOWTO can be found at my homepage
  374.   <http://www.image.dk/~nkbj/> in several formats (including SGML and
  375.   PostScript.) The document has been translated into Japanese by Mr.
  376.   Teruyoshi Fujiwara as part of the JF project
  377.   <ftp://jf.linux.or.jp/pub/JF/other-formats/>.
  378.  
  379.   The FreeBSD Handbook and The FreeBSD FAQ are distributed with FreeBSD.
  380.   They can also be found at FreeBSD Inc. <http://www.freebsd.org/>.
  381.   This site has a lot of other information about FreeBSD too.
  382.  
  383.   The Linux Kernel HOWTO is released as part of The Linux Documentation
  384.   Project <http://sunsite.unc.edu/LDP/>.
  385.  
  386.   8.  Acknowledgments and Copyright
  387.  
  388.   Thanks to the members of the *BSD user group in Denmark
  389.   <http://hotel.prosa.dk/bsd-dk/> for answering the questions of a
  390.   FreeBSD newbie and to Mr. Takeshi Okazaki for bringing the existence
  391.   of U2FS to my attention.
  392.  
  393.   8.1.  Disclaimer
  394.  
  395.   Although the information given in this document is believed to be
  396.   correct, the authors will accept no liability for the content of this
  397.   document. Use the tips and examples given herein at your own risk.
  398.  
  399.   8.2.  Copyright
  400.  
  401.   Copyright (c) 1997, 1998 by Niels Kristian Bech Jensen. This document
  402.   may be distributed only subject to the terms and conditions set forth
  403.   in the LDP license <http://sunsite.unc.edu/LDP/LICENSE.html>.
  404.  
  405.